// g++ 3multhread_test.cpp -O2 -lpthread 
#include <iostream>
#include <thread> 
#include <ctime> 
using namespace std;

void sum(long start,long end,long &ans){
	long s = 0;
	for(long i = start;i<end;++i){
		s+=i;
	}
	ans = s;
} 

const long S = 1000000000;
int main(){
	long ans1,ans2;
	thread t1 = thread(sum,0,S/2,std::ref(ans1));
	thread t2 = thread(sum,S/2,S,std::ref(ans2));
	t1.join();
	t2.join();
	cout<<(ans1+ans2)<<endl;
	

	long ans;
	sum(0,S,ans);
	cout<<ans<<endl;

	return 0;
}
